package com.ocom.ugcapi.controller;

import com.alibaba.fastjson.JSON;
import com.ocom.common.constant.WxServiceUrl;

import com.ocom.common.resp.Result;
import com.ocom.common.vo.payconfig.schoolphone.SchoolPhoneInfoVo;
import com.ocom.common.vo.payconfig.schoolwifiinfo.SchoolWifiInfoVo;

import com.ocom.common.vo.payconfig.cloudcomputing.CloudComputingVo;

import com.ocom.common.vo.ugcapi.GzhUserInfo;
import com.ocom.ugcapi.client.PayConfigClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class SchoolWifiController {

    @Autowired
    private PayConfigClientService payConfigClientService;


    @PostMapping(value = WxServiceUrl.URL_querySchoolWifi)
    public Result querySchoolWifi(@RequestBody Map<String, Object> map) {
        GzhUserInfo userInfo  = (GzhUserInfo)map.get("userInfo");
        int comId = userInfo.getComId().intValue();
        SchoolWifiInfoVo schoolWifiInfoVo = JSON.parseObject(JSON.toJSONString(map), SchoolWifiInfoVo.class);
        schoolWifiInfoVo.setComId(comId);
        schoolWifiInfoVo.setAppName(userInfo.getAppName());
        schoolWifiInfoVo.setPId(Math.toIntExact(userInfo.getPId()));
        schoolWifiInfoVo.setPage(1);
        schoolWifiInfoVo.setSize(1);

        return payConfigClientService.getSchoolWifiList(schoolWifiInfoVo);
    }

    @PostMapping(value = WxServiceUrl.URL_requestSchoolWifi)
    public Result requestSchoolWifi(@RequestBody Map<String, Object> map) {
        GzhUserInfo userInfo  = (GzhUserInfo)map.get("userInfo");
        int comId = userInfo.getComId().intValue();
        String appName = userInfo.getAppName();
        SchoolWifiInfoVo schoolWifiInfoVo = JSON.parseObject(JSON.toJSONString(map), SchoolWifiInfoVo.class);
        schoolWifiInfoVo.setComId(comId);
        schoolWifiInfoVo.setStatus(0);
        schoolWifiInfoVo.setAppName(appName);
        schoolWifiInfoVo.setPId(Math.toIntExact(userInfo.getPId()));
        return payConfigClientService.updateSchoolWifiInfo(schoolWifiInfoVo);
    }

    @PostMapping(value = WxServiceUrl.URL_queryCloudComputing)
    public Result queryCloudComputing(@RequestBody Map<String, Object> map) {
        GzhUserInfo userInfo  = (GzhUserInfo)map.get("userInfo");
        int comId = userInfo.getComId().intValue();
        CloudComputingVo cloudComputingVo = JSON.parseObject(JSON.toJSONString(map), CloudComputingVo.class);
        cloudComputingVo.setComId(comId);
        cloudComputingVo.setAppName(userInfo.getAppName());
        cloudComputingVo.setPId(Math.toIntExact(userInfo.getPId()));
        cloudComputingVo.setPage(1);
        cloudComputingVo.setSize(1);
        return payConfigClientService.getCloudComputingList(cloudComputingVo);

    }

    @PostMapping(value =WxServiceUrl.URL_querySchoolPhone )
    public Result querySchoolPhone(@RequestBody Map<String, Object> map) {
        SchoolPhoneInfoVo schoolPhoneInfoVo = JSON.parseObject(JSON.toJSONString(map), SchoolPhoneInfoVo.class);
        GzhUserInfo userInfo  = (GzhUserInfo)map.get("userInfo");
        int comId = userInfo.getComId().intValue();
        schoolPhoneInfoVo.setComId(comId);
        schoolPhoneInfoVo.setAppName(userInfo.getAppName());
        schoolPhoneInfoVo.setPId(Math.toIntExact(userInfo.getPId()));
        schoolPhoneInfoVo.setPage(1);
        schoolPhoneInfoVo.setSize(1);
        return payConfigClientService.getSchoolPhoneList(schoolPhoneInfoVo);

    }
}